<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="附件管理" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<script language="javascript">
	function doNew(){
		var agentId="${agentId}";
		var extId="${extId}";
		var agentType="${agentType}";
		var code="${code}";
		var accType="${accType}";
		var url;
		if(window.applicationCache){//html5
			url="/business/AccessoryUpload.ihtm?agent_id="+agentId+"&agent_type="+agentType+"&code="+code;
		}else{
			url="/business/AccessoryNew.ihtm?agent_id="+agentId+"&agent_type="+agentType+"&code="+code;
		}
		parent.ShowIframe("附件",url,560,320,"refreshAccWin()");//refreshAccWin是父窗口的
	}
	function refreshWin(){
		window.location=window.location;
	}
	function doEdit(id){
		var url="/business/AccessoryEdit.ihtm?id="+id;
		parent.ShowIframe("附件",url,560,290,"refreshAccWin()");//refreshAccWin是父窗口的
	}
	function doDelete(id){
		parent.ShowConfirm('确认框','确定删除吗？',340,80,"doDelAcc("+id+")");//doDelAcc是父窗口的
	}
	function doDelAct(id){
		var fromUrl=getFromUrl();
		window.location="/business/AccessoryDelete.ihtm?id="+id+"&from_url="+fromUrl;
	}
	function getFromUrl(){
		return encodeURIComponent(window.location);
	}
	function showMe(){
		if(parent.document.getElementById("accessoryFrm")!=null){
			parent.document.getElementById("accessoryFrm").style.height=document.getElementById("mainDiv").offsetHeight+"px";
			parent.resizePopwin();
		}
	}
	function doDownload(id,fileName,sourceName){
		var xmlHttp=createXMLHttpRequest();
		xmlHttp.open("GET", "/FileDownloadLog.ihtm?id="+id);
		xmlHttp.onreadystatechange = function(){
			doDownloadCallback(xmlHttp,fileName,sourceName);
		};
		xmlHttp.send(null);
	}
	function doDownloadCallback(xmlHttp,fileName,sourceName){
    	if (xmlHttp.readyState == 4) {
      		if (xmlHttp.status == 200) {
      			var resTxt=xmlHttp.responseText;
      			if(resTxt=="NO_LOGIN"){
      				ShowAlert('提示框','你还没登录或已经超时，请重新登录。',200,100);
      			}else if(resTxt=="OK"){
      				window.location="/FileDownload.ihtm?file_name="+encodeURIComponent(fileName)+"&source_name="+encodeURIComponent(sourceName);
      			}
			}
		}
	}
</script>
</head>
<body style="margin:0px;padding:0px;" onload="setTimeout('showMe()',100);">
<div class="down" id="mainDiv">
	<h4>附件管理</h4>
	<table class="table-b">
	  	<tr>
		  <th width="22%">文件</th>
		  <th width="22%">资料路径</th>
		  <th width="22%">文件说明</th>
		  <th width="8%">上传人</th>
		  <th width="14%">上传时间</th>
		  <th width="12%">操作</th>
	  	</tr>
		<c:forEach var="item" items="${list}">	
		<tr>  
			<td >
				<c:if test="${item.fileName!=null && item.fileName!=''}"><a href="${item.fileName}" target="_blank">${item.sourceName}</a></c:if>
				<c:if test="${item.fileName==null || item.fileName==''}">${item.sourceName}</c:if>
			</td>
			<td >${item.customPath}</td>
			<td >${item.mark}</td>
			<td >${item.createrName}</td>
			<td ><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm"/></td>
			<td >
				<c:if test="${item.fileName!=null && item.fileName!=''}"><a href="javascript:doDownload('${item.id}','${item.fileName}','${item.sourceName}');">下载</a></c:if>
				<c:if test="${item.fileName==null || item.fileName==''}">下载</c:if>
				<c:if test="${editFlag=='1'}">
					<a href="javascript:doEdit('${item.id}');">编辑</a>
					<a href="javascript:doDelete('${item.id}');">删除</a>
				</c:if>
			</td>
	  	</tr>
   		</c:forEach>
		<c:if test="${editFlag=='1'}">
		<tr>
			<td colspan="6">
				<a href="javascript:doNew();">新增附件</a>
			</td>
		</tr>
		</c:if>	
 	</table>
</div>
</body>
</html>